package com.permission.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

/**
 * redis工具
 * @author jing
 *
 */
@Service("redisPool")
@Slf4j
public class RedisPool {

	@Autowired
	private ShardedJedisPool shardJedisPool;	//Redis封装的一个单例的service
	
	public ShardedJedis instance(){
		return shardJedisPool.getResource();
	}
	
	//关闭方法
	public void safeClose(ShardedJedis shardedJedis){
		try {
			if(shardedJedis != null ){
				shardedJedis.close();
			}
		} catch (Exception e) {
			log.error("return redis resource exception:",e);
		}
	}
}
